﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ZLDC.Common.Estate;
using ZLDC.Topo.BLL.Estate;
using System.Drawing;
using System.Drawing.Drawing2D;
using ZLDC.DAL.Estate;

namespace ZLDC.Estate
{
    public class CHandlerReport
    {
        public static void ChooseMethod()
        {

            string act = _Request.GetString("act", "");

            switch (act)
            {
                #region 部门、个人量化

                case "dept_list":
                    DeptList();
                    break;
                case "Rank_list":
                    Rank_list();
                    break;
                case "Rank_list_action":
                    Rank_list_action();
                    break;
                case "dept_user_list": DeptUserList();
                    break;

                case "user_list":
                    UserList();
                    break;

                case "housing_list_action":
                    HousingListAction(); break;

                case "customer_list_action":
                    CustomerListAction(); break;

                case "SelectTelCount":
                    SelectTelCount(); break;

                case "p_tran_log_list_table":
                    p_tran_log_list_table();
                    break;

                case "p_dayReport_list_table":
                    p_dayReport_list_table();
                    break;

                case "p_call_board_list_table":
                    p_call_board_list_table();
                    break;

                case "DeleteCallBoard":
                    DeleteCallBoard();
                    break;

                #endregion

                #region 桌面量化柱形图

                case "newhousing": NewhousingByWeek();
                    break;
                case "newcustomer": NewcustomerByWeek();
                    break;
                case "hfollow": HousingFlwByWeek();
                    break;
                case "cfollow": CustomerFlwByWeek();
                    break;
                case "looked": LookedByWeek();
                    break;
                case "yeji":
                    GetYeji();
                    break;

                #endregion
            }
        }


        #region 桌面量化柱形图
        private static void NewhousingByWeek()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string username = _Utility.GetInfoBySession().m_sUserName;
            string station = _Utility.GetInfoBySession().m_sStation;
            string firstday = DateTime.Now.ToString("yyyy-MM") + "-01";
            string lastday = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
            string condition = " where  countDate >= DATEADD(wk, DATEDIFF(wk,0, '" + firstday + "'), 0) and countDate <= DATEADD(wk, DATEDIFF(wk,0,'" + lastday + "'), 6)";
            string condition1 = " where  countDate > '" + DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01' and countDate < '" + DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).ToString("yyyy-MM-dd") + "'";
            string chartname = username + " 本月每周新盘量";
            string managesation = ConfigurationSettings.AppSettings["SalesManagerStation"].ToString().Trim();
            bool isContainsSelf = false;
            if (station.Equals("分行经理"))
            {
                isContainsSelf = true;
            }
            string deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(_Utility.GetInfoBySession().m_sDeptID, isContainsSelf);

            if (managesation.Contains(station))
            {
                condition += " and deptId in(" + deptIdList + ")";
                condition1 += " and deptId in(" + deptIdList + ")";
                chartname = _Utility.GetInfoBySession().m_sDeptName + " 本月每周新盘量";
            }
            else
            {
                condition += "and salesmanId='" + userid + "'";
                condition1 += "and salesmanId='" + userid + "'";
            }
            string cachekey = "weekHousingReport_" + userid; DataTable dt = null;
            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                dt = ReportBLL.GetReportCountByWeek("newhousing+mark1", condition);

                if (dt.Rows.Count > 0)
                    _Cache.SetCache(cachekey, dt, 3600 * 1);
            }
            else
            {
                dt = _Cache.GetCache(cachekey) as DataTable;
            }
            string cachekey1 = "monthHousingReport_" + userid;
            DataTable dt1 = null;
            if (_Cache.GetCache(cachekey1) == null || _Cache.GetCache(cachekey1).ToString() == "")
            {
                dt1 = ReportBLL.GetReportCountByMonth("newhousing+mark1", condition1);

                if (dt.Rows.Count > 0)
                    _Cache.SetCache(cachekey1, dt1, 3600 * 1);
            }
            else
            {
                dt1 = _Cache.GetCache(cachekey1) as DataTable;
            }

            CreateChart(userid, chartname, dt, dt1);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("../Chart/" + userid + ".jpg?" + DateTime.Now.ToString());
            HttpContext.Current.Response.End();

        }

        private static void CreateChart(int userid, string chartname, DataTable dt, DataTable dt1)
        {
            int height = 200, width = 350;
            Bitmap image = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(image);

            try
            {
                g.Clear(Color.White);

                Font font = new Font("Arial", 10, FontStyle.Regular);
                Font font1 = new Font("Arial", 9, FontStyle.Bold);

                LinearGradientBrush brush = new
                LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Black, Color.BlueViolet, 1.2f, true);
                g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);

                g.DrawString(chartname, font1, brush, new PointF(100, 10));
                g.DrawRectangle(new Pen(Color.Blue), 0, 0, image.Width - 1, image.Height - 1);


                Pen mypen = new Pen(brush, 1);


                int dataCount = dt.Rows.Count;
                g.DrawLine(mypen, 15, 150, width - 50, 150);
                g.DrawLine(mypen, 15, 30, 15, 150);
                StringFormat drawFormat = new StringFormat();
                drawFormat.FormatFlags = StringFormatFlags.DirectionVertical;


                int dataMax = 0;
                for (int i = 0; i < dataCount; i++)
                {
                    int itemdata = Convert.ToInt32(dt.Rows[i][3]);
                    if (dataMax < itemdata)
                        dataMax = itemdata;
                }
                dataMax = dataMax + 3;

                Font font2 = new System.Drawing.Font("Arial", 10, FontStyle.Bold);
                g.DrawString(dataMax.ToString(), font2, Brushes.Black, 15, 20);
                int left = width / (dataCount + 1);

                for (int i = 0; i < dataCount; i++)
                {
                    int itemdata = Convert.ToInt32(dt.Rows[i][3]);
                    DateTime itemdate1 = Convert.ToDateTime(dt.Rows[i][1].ToString());
                    DateTime itemdate2 = Convert.ToDateTime(dt.Rows[i][2].ToString());


                    string xname = itemdate1.Day.ToString() + "-" + itemdate2.Day.ToString() + "日";
                    if (dataMax > 0)
                    {
                        g.DrawString(xname, new Font("Arial", 9), new SolidBrush(Color.Black), (i + 1) * left - 25, 155);
                        g.FillRectangle(new SolidBrush(Color.Red), (i + 1) * (left - 5), 150 - 120 * itemdata / dataMax, 13, 120 * itemdata / dataMax);
                        g.DrawString(itemdata.ToString(), font2, Brushes.Red, (i + 1) * left - 5, 150 - 120 * itemdata / dataMax - 15);

                    }
                }

                string strMonthContent = "";
                for (int j = 0; j < dt1.Rows.Count; j++)
                {
                    string month = dt1.Rows[j][0].ToString();
                    string monthcount = dt1.Rows[j][1].ToString();
                    strMonthContent += month + "月:" + monthcount + "    ";
                }

                g.DrawString(strMonthContent, new Font("Arial", 9), new SolidBrush(Color.Blue), 15, 175);

                string chartDirect = HttpContext.Current.Request.MapPath("../Chart/");
                if (!System.IO.Directory.Exists(chartDirect))
                {
                    System.IO.Directory.CreateDirectory(chartDirect);
                }
                string imagePath = chartDirect + userid + ".jpg";

                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                image.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {

            }
            finally
            {
                g.Dispose();
                image.Dispose();
            }
        }


        private static void LookedByWeek()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string username = _Utility.GetInfoBySession().m_sUserName;
            string station = _Utility.GetInfoBySession().m_sStation;
            string firstday = DateTime.Now.ToString("yyyy-MM") + "-01";
            string lastday = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
            string condition = " where  countDate >= DATEADD(wk, DATEDIFF(wk,0, '" + firstday + "'), 0) and countDate <= DATEADD(wk, DATEDIFF(wk,0,'" + lastday + "'), 6)";
            string condition1 = " where  countDate > '" + DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01' and countDate < '" + DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).ToString("yyyy-MM-dd") + "'";
            string chartname = username + " 本月每周看楼量";
            string managesation = ConfigurationSettings.AppSettings["SalesManagerStation"].ToString().Trim();
            bool isContainsSelf = false;
            if (station.Equals("分行经理"))
            {
                isContainsSelf = true;
            }
            string deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(_Utility.GetInfoBySession().m_sDeptID, isContainsSelf);

            if (managesation.Contains(station))
            {
                condition += " and deptId in(" + deptIdList + ")";
                condition1 += " and deptId in(" + deptIdList + ")";
                chartname = _Utility.GetInfoBySession().m_sDeptName + " 本月每周看楼量";
            }
            else
            {
                condition += "and salesmanId='" + userid + "'";
                condition1 += "and salesmanId='" + userid + "'";
            }
            DataTable dt = ReportBLL.GetReportCountByWeek("looked", condition);
            DataTable dt1 = ReportBLL.GetReportCountByMonth("looked", condition1);

            CreateChart(userid, chartname, dt, dt1);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("../Chart/" + userid + ".jpg?" + DateTime.Now.ToString());
            HttpContext.Current.Response.End();
        }

        private static void CustomerFlwByWeek()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string username = _Utility.GetInfoBySession().m_sUserName;
            string station = _Utility.GetInfoBySession().m_sStation;
            string firstday = DateTime.Now.ToString("yyyy-MM") + "-01";
            string lastday = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
            string condition = " where  countDate >= DATEADD(wk, DATEDIFF(wk,0, '" + firstday + "'), 0) and countDate < =DATEADD(wk, DATEDIFF(wk,0,'" + lastday + "'), 6)";
            string condition1 = " where  countDate > '" + DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01' and countDate < '" + DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).ToString("yyyy-MM-dd") + "'";
            string chartname = username + " 本月每周客跟进量";
            string managesation = ConfigurationSettings.AppSettings["SalesManagerStation"].ToString().Trim();
            bool isContainsSelf = false;
            if (station.Equals("分行经理"))
            {
                isContainsSelf = true;
            }
            string deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(_Utility.GetInfoBySession().m_sDeptID, isContainsSelf);

            if (managesation.Contains(station))
            {
                condition += " and deptId in(" + deptIdList + ")";
                condition1 += " and deptId in(" + deptIdList + ")";
                chartname = _Utility.GetInfoBySession().m_sDeptName + " 本月每周客跟进量";
            }
            else
            {
                condition += "and salesmanId='" + userid + "'";
                condition1 += "and salesmanId='" + userid + "'";
            }
            DataTable dt = ReportBLL.GetReportCountByWeek("cfollow", condition);
            DataTable dt1 = ReportBLL.GetReportCountByMonth("cfollow", condition1);

            CreateChart(userid, chartname, dt, dt1);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("../Chart/" + userid + ".jpg?" + DateTime.Now.ToString());
            HttpContext.Current.Response.End();
        }

        private static void HousingFlwByWeek()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string username = _Utility.GetInfoBySession().m_sUserName;
            string station = _Utility.GetInfoBySession().m_sStation;
            string firstday = DateTime.Now.ToString("yyyy-MM") + "-01";
            string lastday = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
            string condition = " where  countDate >= DATEADD(wk, DATEDIFF(wk,0, '" + firstday + "'), 0) and countDate <= DATEADD(wk, DATEDIFF(wk,0,'" + lastday + "'), 6)";
            string condition1 = " where  countDate > '" + DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01' and countDate < '" + DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).ToString("yyyy-MM-dd") + "'";
            string chartname = username + " 本月每周盘跟进量";
            string managesation = ConfigurationSettings.AppSettings["SalesManagerStation"].ToString().Trim();
            bool isContainsSelf = false;
            if (station.Equals("分行经理"))
            {
                isContainsSelf = true;
            }
            string deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(_Utility.GetInfoBySession().m_sDeptID, isContainsSelf);

            if (managesation.Contains(station))
            {
                condition += " and deptId in(" + deptIdList + ")";
                condition1 += " and deptId in(" + deptIdList + ")";
                chartname = _Utility.GetInfoBySession().m_sDeptName + " 本月每周盘跟进量";
            }
            else
            {
                condition += "and salesmanId='" + userid + "'";
                condition1 += "and salesmanId='" + userid + "'";
            }
            DataTable dt = ReportBLL.GetReportCountByWeek("hfollow", condition);
            DataTable dt1 = ReportBLL.GetReportCountByMonth("hfollow", condition1);

            CreateChart(userid, chartname, dt, dt1);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("../Chart/" + userid + ".jpg?" + DateTime.Now.ToString());
            HttpContext.Current.Response.End();
        }

        private static void NewcustomerByWeek()
        {
            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            string username = _Utility.GetInfoBySession().m_sUserName;
            string station = _Utility.GetInfoBySession().m_sStation;
            string firstday = DateTime.Now.ToString("yyyy-MM") + "-01";
            string lastday = DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd");
            string condition = " where  countDate >= DATEADD(wk, DATEDIFF(wk,0, '" + firstday + "'), 0) and countDate <= DATEADD(wk, DATEDIFF(wk,0,'" + lastday + "'), 6)";
            string condition1 = " where  countDate > '" + DateTime.Now.AddMonths(-2).ToString("yyyy-MM") + "-01' and countDate < '" + DateTime.Now.AddDays(1 - DateTime.Now.Day).AddMonths(1).ToString("yyyy-MM-dd") + "'";
            string chartname = username + " 本月每周新客量";
            string managesation = ConfigurationSettings.AppSettings["SalesManagerStation"].ToString().Trim();
            bool isContainsSelf = false;
            if (station.Equals("分行经理"))
            {
                isContainsSelf = true;
            }
            string deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(_Utility.GetInfoBySession().m_sDeptID, isContainsSelf);

            if (managesation.Contains(station))
            {
                condition += " and deptId in(" + deptIdList + ")";
                condition1 += " and deptId in(" + deptIdList + ")";
                chartname = _Utility.GetInfoBySession().m_sDeptName + " 本月每周新客量";
            }
            else
            {
                condition += "and salesmanId='" + userid + "'";
                condition1 += "and salesmanId='" + userid + "'";
            }

            string cachekey = "newweekcustomer" + userid; DataTable dt = null;
            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                dt = ReportBLL.GetReportCountByWeek("newcustomer+mark2", condition);
                if (dt.Rows.Count > 0)
                    _Cache.SetCache(cachekey, dt, 3600 * 1);
            }
            else
            {
                dt = _Cache.GetCache(cachekey) as DataTable;
            }
            string cachekey1 = "newmonthcustomer" + userid; DataTable dtmonth = null;
            if (_Cache.GetCache(cachekey1) == null || _Cache.GetCache(cachekey1).ToString() == "")
            {
                dtmonth = ReportBLL.GetReportCountByMonth("newcustomer+mark2", condition1);
                if (dtmonth.Rows.Count > 0)
                    _Cache.SetCache(cachekey1, dtmonth, 3600 * 1);
            }
            else
            {
                dtmonth = _Cache.GetCache(cachekey1) as DataTable;
            }


            CreateChart(userid, chartname, dt, dtmonth);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write("../Chart/" + userid + ".jpg?" + DateTime.Now.ToString());
            HttpContext.Current.Response.End();
        }
        #endregion

        #region 部门、个人量化

        private static void DeptList()
        {
            string deptId = _Request.GetString("deptId", ""); string startdate = _Request.GetString("addDate1", "");
            string enddate = _Request.GetString("addDate2", "");

            bool isContainsSelf = false; if (deptId == "")
                deptId = _Utility.GetInfoBySession().m_sDeptID;
            else
                isContainsSelf = true;


            if (_Request.GetInt("isContainsSelf", 0) > 0) isContainsSelf = false;


            string type = ZLDC.DAL.Estate.DeptDAL.GetDeptType(deptId);
            if (type == "分行")
                isContainsSelf = true;


            string deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(deptId, isContainsSelf);

            string condition = " where 1=1 ";
            if (deptId != "")
                condition += " and deptid in (" + deptIdList + ")";




            if (startdate != "" && enddate != "")
                condition += " and DATEDIFF(dd, countDate, '" + startdate + "') <= 0 and DATEDIFF(dd, countDate, '" + enddate + "') >= 0";


            HttpContext.Current.Session["dept_list_report"] = condition;


            string json = ZLDC.Topo.BLL.Estate.ReportBLL.p_report_dept_list_table(1, condition, _Convert.ToInt(deptId, 0));

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }





        private static void DeptUserList()
        {
            int deptId = _Request.GetInt("deptId", 0); string startdate = _Request.GetString("addDate1", "");
            string enddate = _Request.GetString("addDate2", "");

            string condition = " where 1=1 ";
            if (deptId > 0)
                condition += " and t.deptid = " + deptId.ToString();
            if (startdate != "" && enddate != "")
                condition += " and DATEDIFF(dd, countDate, '" + startdate + "') <= 0 and DATEDIFF(dd, countDate, '" + enddate + "') >= 0";
            HttpContext.Current.Session["deptuserlist"] = condition;
            string json = ZLDC.Topo.BLL.Estate.ReportBLL.p_report_dept_list_table(2, condition, deptId);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void UserList()
        {
            string station = _Utility.GetInfoBySession().m_sStation; string deptId = _Utility.GetInfoBySession().m_sDeptID;
            string userNoAndName = _Request.GetString("userNoAndName", ""); string tempDeptId = _Request.GetString("deptid", ""); int typeid = _Request.GetInt("typeid", 0);
            string userName = string.Empty; string userNo = string.Empty; int tempUserId = 0; if (userNoAndName != "")
            {
                _Utility.GetUserNoAndUserName(userNoAndName.Trim(), out userName, out userNo);
                if (_Convert.ToInt(userName, 0) > 0)
                    tempUserId = _Convert.ToInt(userName, 0);
                else
                    tempUserId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserName(userName, userNo);
            }

            string salesmanid_list = "";
            string startdate = _Request.GetString("addDate1", "");
            string enddate = _Request.GetString("addDate2", "");

            if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station) || _Utility.GetInfoBySession().m_sRoleID == "1" || ZLDC.Common.BaseUser.UserInfo.GetPopedom("部门量化"))
            {
                if (typeid == 0)
                    typeid = 2;

                if (tempDeptId != "" || tempUserId > 0)
                {
                    if (tempDeptId != "")
                        salesmanid_list = ZLDC.Topo.BLL.Estate.UserBLL.GetUserListByDeptid(tempDeptId);

                    if (tempUserId > 0)
                    {
                        salesmanid_list = tempUserId.ToString();
                        tempDeptId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserInfoByUserID(tempUserId).Dept_id.ToString();
                    }
                }
                else
                {
                    salesmanid_list = ZLDC.Topo.BLL.Estate.UserBLL.GetUserListByDeptid(deptId);

                    tempDeptId = deptId;
                }
            }
            else
            {
                if (typeid == 0)
                    typeid = 3;

                salesmanid_list = _Utility.GetInfoBySession().m_sUserID;
                tempDeptId = deptId;
            }

            string condition = "where 1=1 ";

            condition += " and salesmanid in(" + salesmanid_list + ")";

            if (startdate != "" && enddate != "")
                condition += " and DATEDIFF(dd, countDate, '" + startdate + "') <= 0 and DATEDIFF(dd, countDate, '" + enddate + "') >= 0";


            HttpContext.Current.Session["userlist_report"] = condition;
            HttpContext.Current.Session["userlist_typeid"] = typeid;


            string json = ZLDC.Topo.BLL.Estate.ReportBLL.p_report_dept_list_table(typeid, condition, _Convert.ToInt(tempDeptId, 0));

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void Rank_list()
        {
            string deptId = _Request.GetString("deptId", ""); string startdate = _Request.GetString("addDate1", "");
            string enddate = _Request.GetString("addDate2", "");
            string orderbyName = _Request.GetString("orderbyName", ""); string orderbyType = _Request.GetString("orderbyType", "");
            string type = ZLDC.DAL.Estate.DeptDAL.GetDeptType(deptId);

            int typeid = 1;


            bool isContainsSelf = false; if (deptId == "")
                deptId = _Utility.GetInfoBySession().m_sDeptID;
            else
                isContainsSelf = true;



            if (_Request.GetInt("isContainsSelf", 0) > 0) isContainsSelf = false;


            if (type == "分行")
            {
                isContainsSelf = true;
                typeid = 2;
            }



            string deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(deptId, isContainsSelf);


            string condition = " where 1=1 ";
            if (deptId != "")
                condition += " and deptid in (" + deptIdList + ")";


            if (startdate != "" && enddate != "")
                condition += " and DATEDIFF(dd, countDate, '" + startdate + "') <= 0 and DATEDIFF(dd, countDate, '" + enddate + "') >= 0";
            orderbyName = orderbyName + " " + orderbyType;


            HttpContext.Current.Session["rank_list"] = condition;
            HttpContext.Current.Session["rank_list_typeid"] = typeid;

            string json = ZLDC.Topo.BLL.Estate.ReportBLL.p_rank_list_table(typeid, condition, orderbyName, _Convert.ToInt(deptId, 0));

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void Rank_list_action()
        {
            string deptId = _Request.GetString("deptId", ""); string startdate = _Request.GetString("addDate1", "");
            string enddate = _Request.GetString("addDate2", "");
            string orderbyName = _Request.GetString("orderbyName", ""); string orderbyType = _Request.GetString("orderbyType", ""); string item = _Request.GetString("item", "");
            int typeid = 1;

            int parentId = 0;

            if (deptId == "")
                deptId = _Utility.GetInfoBySession().m_sDeptID;


            string typeName = ZLDC.DAL.Estate.DeptDAL.GetDeptType(deptId);

            string deptIdList = "";


            if (item == "4")
            {

                if (typeName == "营业大部")
                {
                    deptIdList = GetAllChildrenDeptByType(deptId, "营业部");
                }
                else
                {
                    deptIdList = ZLDC.Common.BaseUser.UserInfo.GetBusinessDeptId();
                }

                parentId = ZLDC.Common.BaseUser.UserInfo.GetFatherYY_id(deptId);


            }
            else if (item == "3")
            {

                if (typeName == "分行")
                {
                    int QY_Id = ZLDC.Common.BaseUser.UserInfo.GetFatherQY_id(deptId);
                    parentId = ZLDC.Common.BaseUser.UserInfo.GetFatherYY_id(QY_Id.ToString());
                    deptIdList = GetAllChildrenDeptByType(parentId.ToString(), "区域");
                }
                else if (typeName == "区域")
                {
                    parentId = ZLDC.Common.BaseUser.UserInfo.GetFatherYY_id(deptId);
                    deptIdList = GetAllChildrenDeptByType(parentId.ToString(), "区域");
                }
                else
                {
                    deptIdList = GetAllChildrenDeptByType(deptId, "区域");
                }


                #region 以前取部门






                #endregion

            }
            else if (item == "2")
            {

                if (typeName == "分行")
                {
                    parentId = ZLDC.Common.BaseUser.UserInfo.GetFatherQY_id(deptId);
                    deptIdList = GetAllChildrenDeptByType(parentId.ToString(), "分行");

                }
                else
                {
                    deptIdList = GetAllChildrenDeptByType(deptId, "分行");
                }

                #region 以前取部门





















                #endregion

            }
            else if (item == "1")
            {

                if (typeName == "分行")
                {
                    deptIdList = deptId;

                }
                else
                {
                    deptIdList = GetAllChildrenDeptByType(deptId, "分行");
                }

                #region 以前取部门








                #endregion


                typeid = 2;
            }

            if (deptIdList == "")
            {
                deptIdList = "''";
            }
            string condition = " where 1=1 ";

            condition += " and deptid in (" + deptIdList + ")";

            if (item == "1" && parentId > 0)
            {
                string deptType = ZLDC.DAL.Estate.DeptDAL.GetDeptType(parentId.ToString());
                if (deptType == "营业部")
                {
                    condition += " and dept not like '%区%'";
                }
                else if (deptType == "营业大部")
                {
                    condition += " and (dept not like '%部%' and dept not like '%区%')";
                }

            }


            #region 功能不明确
            /*
            if (typeName == "营业大部" && deptId!=_Utility.GetInfoBySession().m_sDeptID) 
            {
                string deptType=ZLDC.DAL.Estate.DeptDAL.GetDeptType(deptId);
                
                if (item == "2" || item=="1")                {
                    if (deptType == "营业部")
                    {
                        if (deptId != _Utility.GetInfoBySession().m_sDeptID)
                        {
                            string[] ArrStr = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(deptId, false).Split(',');
                            deptIdList = "";
                            for (int i = 0; i < ArrStr.Length; i++)
                            {
                                string deptid = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(ArrStr[i], false);
                                if (deptid != "")
                                {
                                        deptIdList = deptIdList + deptid + ",";
                                }
                            }

                            if (deptIdList != "") 
                            {
                                deptIdList = deptIdList.TrimEnd(',');
                            }
                            condition += " and deptid  in (" + deptIdList + ")";

                        }


                    }
                    else if (deptType == "区域")
                    {
                        if (deptId != _Utility.GetInfoBySession().m_sDeptID)
                        {
                            deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(deptId, false);

                            condition += " and deptid  in (" + deptIdList + ")";


                        }


                    }
                    else  if(deptType=="分行")
                    {
                        if (item == "1")
                        {
                            deptIdList = deptId;
                            condition += " and deptid  in (" + deptIdList + ")";

                        }
                        else if (item == "2") 
                        {
                            parentId =_Convert.ToInt(deptId);
                        }
                    }


                }
                else if(item=="3")                {
                    if (deptType == "营业部")
                    {
                        if (deptId != _Utility.GetInfoBySession().m_sDeptID)
                        {
                            deptIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(deptId, false);
                            
                        }
                        condition += " and deptid  in (" + deptIdList + ")";

                    }
                    else if (deptType == "区域")
                    {
                        if (deptId != _Utility.GetInfoBySession().m_sDeptID)
                        {
                            deptIdList = deptId;
                            parentId =_Convert.ToInt(deptId);
                        }
                    }
                }


            }
                        if ((item == "2" || item=="1") && typeName == "营业部")
            { 
                 string parentIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(parentId.ToString(), false);
                 if (parentIdList == "")
                 {
                     parentIdList = ZLDC.Common.BaseUser.UserInfo.getFirstChildDept(_Utility.GetInfoBySession().m_sDeptID, false);
                 }
                 condition += " and deptid not in (" + parentIdList + ")";
            }
            */
            #endregion

            if (startdate != "" && enddate != "")
                condition += " and DATEDIFF(dd, countDate, '" + startdate + "') <= 0 and DATEDIFF(dd, countDate, '" + enddate + "') >= 0";
            orderbyName = "SUM(" + orderbyName + ") " + orderbyType;



            HttpContext.Current.Session["rank_list"] = condition;
            HttpContext.Current.Session["rank_list_typeid"] = typeid;
            HttpContext.Current.Session["rank_list_orderbyName"] = orderbyName;


            string json = ZLDC.Topo.BLL.Estate.ReportBLL.p_rank_list_action_table(typeid, condition, orderbyName, parentId);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();

        }



        private static void HousingListAction()
        {
            string json = "";

            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int reprottypeid = _Request.GetInt("reporttypeid", 0); int salesmanid = _Request.GetInt("salesmanid", 0);
            int salesmanno = _Request.GetInt("salesmanno", 0);
            int deptid = _Request.GetInt("deptid", 0);
            string station = _Utility.GetInfoBySession().m_sStation; string IdList1 = "";
            if (deptid > 0)
            {
                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptid.ToString());
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {
                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                {
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
                }
            }

            string orderByName = _Request.GetString("orderByName", "");
            string orderByType = _Request.GetString("orderByType", "desc");
            string startdate = _Request.GetString("addDate1", ""); string enddate = _Request.GetString("addDate2", "");

            string IdList = "";

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看量化详情"))
                IdList = IdList1;
            else
                IdList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);



            if (reprottypeid >= 0)
            {
                string condition = " where 1=1 ";
                int typeid = reprottypeid;
                if (reprottypeid == 0 || reprottypeid == 1 || reprottypeid == 11 || reprottypeid == 4 || reprottypeid == 14)
                {
                    if (reprottypeid == 1 || reprottypeid == 11)
                    {
                        typeid = 5;
                        condition += " and tradetype=1";
                    }
                    else if (reprottypeid == 4 || reprottypeid == 14)
                    {
                        typeid = 14;
                        condition += " and tradetype=2";
                    }
                    else if (reprottypeid == 0)
                    {
                        typeid = 514;
                        condition += " and tradetype in(1,2)";
                    }

                    if (salesmanid > 0)
                        condition += " and userid=" + salesmanid;
                    if (deptid > 0)
                    {
                        if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station) || ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看量化详情"))
                        {

                            if (deptid > 0)
                                condition += " and deptid in(" + IdList1 + ")   and deptid in(" + IdList + ") ";
                            else
                                condition += " and deptid in(" + IdList + ") ";
                        }
                        else
                        {
                            condition += " and deptid=" + deptid + " ";
                        }
                    }

                    if (startdate != "" && enddate != "")
                        condition += " and countdate >= '" + startdate + "' and countdate < '" + _Convert.ToDateTime(enddate, DateTime.Today).AddDays(1).ToString("yyyy-MM-dd") + "'";
                }
                else
                {
                    if (salesmanid > 0)
                        condition += " and userid=" + salesmanid;

                    if (deptid > 0)
                    {
                        if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station) || ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看量化详情"))
                        {

                            if (deptid > 0)
                                condition += " and deptid in(" + IdList1 + ")   and deptid in(" + IdList + ") ";
                            else
                                condition += " and deptid in(" + IdList + ") ";
                        }
                        else
                        {
                            condition += " and deptid=" + deptid + " ";
                        }
                    }
                    if ((reprottypeid == 2 || reprottypeid == 12))
                    {
                        typeid = 7;

                        condition += " and countdate >= '" + startdate + "' and countdate < '" + _Convert.ToDateTime(enddate, DateTime.Today).AddDays(1).ToString("yyyy-MM-dd") + "'";
                    }

                    if ((reprottypeid == 3 || reprottypeid == 13))
                    {
                        typeid = 8;
                        condition += " and countdate >= '" + startdate + "' and countdate < '" + _Convert.ToDateTime(enddate, DateTime.Today).AddDays(1).ToString("yyyy-MM-dd") + "'";
                    }
                    if (reprottypeid == 20)
                    {
                        typeid = 9;
                        condition += " and countdate >= '" + startdate + "' and countdate < '" + _Convert.ToDateTime(enddate, DateTime.Today).AddDays(1).ToString("yyyy-MM-dd") + "'";

                    }
                    if (reprottypeid == 21)
                    {
                        typeid = 19;
                        condition += " and countdate >= '" + startdate + "' and countdate < '" + _Convert.ToDateTime(enddate, DateTime.Today).AddDays(1).ToString("yyyy-MM-dd") + "'";
                    }

                }

                json = ZLDC.Topo.BLL.Estate.ReportBLL.p_quantificationlog_type_table(typeid, page, pagesize, condition);
            }

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void CustomerListAction()
        {
            string json = "";

            int userid = _Convert.ToInt(_Utility.GetInfoBySession().m_sUserID);
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            int reprottypeid = _Request.GetInt("reprottypeid", 0); int salesmanid = _Request.GetInt("salesmanid", 0);
            int deptid = _Request.GetInt("deptid", 0);

            string station = _Utility.GetInfoBySession().m_sStation;
            string IdList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);

            string IdList1 = ""; if (deptid > 0)
            {
                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptid.ToString());
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {
                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                {
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
                }
            }

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看量化详情"))
                IdList = IdList1;

            string condition = " where 1=1 ";

            if (salesmanid > 0)
                condition += " and userid=" + salesmanid;
            if (deptid > 0)
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station) || ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看量化详情"))
                {
                    if (deptid > 0) condition += " and deptid in(" + IdList1 + ") and deptid in(" + IdList + ") ";
                    else
                        condition += " and deptid in(" + IdList + ") ";
                }
                else
                {
                    condition += " and deptid=" + deptid + " ";
                }
            }

            int typeid = 0; if (reprottypeid == 1)
            {
                typeid = 6;
                condition += " and tradetype='求购'";
            }
            else if (reprottypeid == 2)
            {
                typeid = 15;
                condition += " and tradetype='求租'";
            }
            else if (reprottypeid == 17)
            {
                typeid = 17;
                condition += " and tradetype='求购'";
            }
            else if (reprottypeid == 18)
            {
                typeid = 18;
                condition += " and tradetype='求租'";
            }
            else if (reprottypeid == 0)
            {
                typeid = 615;
                condition += " and tradetype in ('求租','求购') ";
            }

            string startdate = _Request.GetString("addDate1", ""); string enddate = _Request.GetString("addDate2", "");
            if (startdate != "" && enddate != "")
                condition += " and countdate >= '" + startdate + "' and countdate < '" + _Convert.ToDateTime(enddate, DateTime.Today).AddDays(1).ToString("yyyy-MM-dd") + "'";

            json = ZLDC.Topo.BLL.Estate.ReportBLL.p_quantificationlog_type_table(typeid, page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void p_tran_log_list_table()
        {
            string json = "";
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string condition = " where 1=1 ";
            string username = _Request.GetString("username", "");



            if (username != "")
            {
                string userName = string.Empty; string userNo = string.Empty; _Utility.GetUserNoAndUserName(username.Trim(), out userName, out userNo);


                condition += "  and user_name='" + userName + "' ";


            }
            string userfromname = _Request.GetString("userfromname", "");
            if (userfromname != "")
            {
                string userName = string.Empty; string userNo = string.Empty; _Utility.GetUserNoAndUserName(userfromname.Trim(), out userName, out userNo);

                condition += " and user_from_name like '" + userName + "%' ";
            }
            string usertoname = _Request.GetString("usertoname", "");
            if (usertoname != "")
            {
                string userName = string.Empty; string userNo = string.Empty; _Utility.GetUserNoAndUserName(usertoname.Trim(), out userName, out userNo);
                condition += " and user_to_name='" + userName + "' ";
            }
            string type = _Request.GetString("type", "");
            if (type != "全部" && type != "")
            {

                condition += " and opr_type='" + type + "' ";
            }
            string startTime = _Request.GetString("startTime", "");
            string endTime = _Request.GetString("EndTime", "");

            if (startTime != "" && endTime != "")
            {
                condition += " and opr_date between '" + startTime + " 00:00:00" + "' and '" + endTime + " 23:59:59" + "' ";
            }

            json = ZLDC.Topo.BLL.Estate.TranLogBLL.p_tran_log_list_table(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void SelectTelCount()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string StratTime = _Request.GetString("startTime", "");
            string EndTIME = _Request.GetString("EndTime", "");
            string deptid = _Request.GetString("deptname", "");
            string USERID = _Request.GetString("UserName", "");

            string IdList1 = "";
            if (_Convert.ToInt(deptid, 0) > 0)
            {
                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptid);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {
                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                {
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
                }
            }
            string condition = "where housingid>0 ";
            string station = _Utility.GetInfoBySession().m_sStation;

            if (ZLDC.Common.BaseUser.UserInfo.GetPopedom("查看全部电话数"))
            {
                if (deptid != "")
                {
                    condition += " and deptid in (" + IdList1 + ") ";
                }
            }
            else
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                {
                    string IdList = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);

                    if (deptid != "")
                    {
                        condition += " and deptid in(" + IdList1 + ")   and deptid in(" + IdList + ") ";
                    }
                    else
                    {
                        condition += " and deptid in(" + IdList + ") ";
                    }
                }
                else
                {

                    condition += " and lookerid ='" + _Utility.GetInfoBySession().m_sUserID + "' ";

                }



            }
            if (StratTime != "" && EndTIME != "")
            {
                condition += " and seedate >='" + StratTime + " 00:00:00 ' and seedate <= '" + EndTIME + " 23:59:59" + "' ";
            }
            if (USERID != "")
            {
                if (_Convert.ToInt(USERID.ToString(), 0) > 0)
                {
                    condition += " AND lookerid='" + USERID + "' ";
                }
                else
                {
                    string userName = string.Empty; string userNo = string.Empty; int userId = 0; _Utility.GetUserNoAndUserName(USERID.Trim(), out userName, out userNo);
                    if (userName == "")
                    {
                        condition += " AND lookerid='" + USERID + "' ";
                    }
                    else
                    {
                        userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserNo(userNo);

                        condition += " AND lookerid='" + userId.ToString() + "' ";
                    }
                }
            }

            string json = ZLDC.Topo.BLL.Estate.HousingBLL.p_v_LookTelLog_list_table(page, pagesize, condition);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void p_dayReport_list_table()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);
            string sTime = _Request.GetString("sTime", "");
            string eTime = _Request.GetString("eTime", "");
            int deptid = _Request.GetInt("deptid", 0);
            string replyflag = _Request.GetString("replyflag", "");
            string username = _Request.GetString("userName", "");
            string condition = "";
            string station = _Utility.GetInfoBySession().m_sStation;

            string USERID = _Request.GetString("UserName", "");

            string IdList1 = ""; if (deptid > 0)
            {
                DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptid.ToString()); for (int i = 0; i < dt.Rows.Count; i++)
                {
                    if (dt.Rows[i]["id"].ToString() != "")
                    {

                        IdList1 += dt.Rows[i]["id"].ToString() + ",";
                    }
                }
                if (IdList1 != "")
                {
                    IdList1 = IdList1.Substring(0, IdList1.Length - 1);
                }

            }
            if (station.Contains("软件工程师（楼盘）"))
            {
                condition = " where 1=1 ";
            }
            else
            {
                if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(station))
                {
                    string deptid_list = CacheUtility.Cache_GetAllChildDept(_Utility.GetInfoBySession().m_sDeptID);
                    condition = " where adddeptid in(" + deptid_list + ")";
                }
                else
                {
                    condition = "where adduserid=" + _Utility.GetInfoBySession().m_sUserID + "";
                }
            }

            if (sTime != "" && eTime != "")
                condition += " and reportDate between '" + sTime + " 00:00:00" + "' and '" + eTime + " 23:59:59" + "' ";

            if (deptid > 0)
                condition += " and adddeptid in(" + IdList1 + ")";

            if (replyflag != "")
                condition += " and readflag ='" + replyflag + "' ";

            if (username != "")
            {
                string userName = string.Empty; string userNo = string.Empty; int userId = 0; _Utility.GetUserId(username.Trim(), out userName, out userNo);
                userId = ZLDC.Topo.BLL.Estate.UserBLL.GetUserIDByUserNo(userNo);
                condition += " and adduserid=" + userId + " ";
            }

            string json = ZLDC.Topo.BLL.Estate.DayReportBLL.p_dayReport_list_table(page, pagesize, condition);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void p_call_board_list_table()
        {
            int page = _Request.GetInt("page", 0);
            int pagesize = _Request.GetInt("pagesize", 0);

            string condition = "";

            if (_Utility.GetWebConfigSetting("SalesManagerStation").Contains(_Utility.GetInfoBySession().m_sStation))
            {
                condition = " where msg_type = 1 " + " and user_id = " + _Utility.GetInfoBySession().m_sUserID + "";

            }
            else
            {
                condition = " where msg_type=1  ";
            }

            string json = ZLDC.Topo.BLL.Estate.CallBoardBLL.p_call_board_list_table(page, pagesize, condition);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        public static void DeleteCallBoard()
        {
            int ID = _Request.GetInt("ID", 0);
            string json = ZLDC.Topo.BLL.Estate.CallBoardBLL.DeleteCallBoard(ID);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        private static void GetYeji()
        {
            string userEHRid = _Utility.GetInfoBySession().m_sEHRUserID;
            string detpid = _Utility.GetInfoBySession().m_sDeptID;
            string fgs = _Utility.GetInfoBySession().m_sFgs;
            DateTime now = DateTime.Now;
            DateTime d1 = new DateTime(now.Year, now.Month, 1);
            DateTime d2 = d1.AddMonths(1).AddDays(-1);

            string json = "";
            string cachekey = "GetYejiByDeptId" + detpid + "_UserId" + userEHRid;

            if (_Cache.GetCache(cachekey) == null || _Cache.GetCache(cachekey).ToString() == "")
            {
                json = ZLDC.Topo.BLL.Estate.ReportBLL.GetYeji(userEHRid, detpid, fgs, d1.ToString("yyyy-MM-dd"), d2.ToString("yyyy-MM-dd"));
                if (json != "")
                    _Cache.SetCache(cachekey, json, 3600 * 1);
            }
            else
                json = _Cache.GetCache(cachekey).ToString();

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.Write(json);
            HttpContext.Current.Response.End();
        }

        #endregion



        private static string GetAllChildrenDept(int deptid)
        {
            string IdList = "";
            DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDept(deptid.ToString());
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["id"].ToString() != "")
                {
                    IdList += dt.Rows[i]["id"].ToString() + ",";
                }
            }
            if (IdList != "")
            {
                IdList = IdList.Substring(0, IdList.Length - 1);
            }
            return IdList;
        }



        private static string GetAllChildrenDeptByType(string deptid, string type)
        {
            string IdList = "";
            DataTable dt = ZLDC.DAL.Estate.DeptDAL.getGetAllChildrenDeptByType(deptid, type);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["id"].ToString() != "")
                {
                    IdList += dt.Rows[i]["id"].ToString() + ",";
                }
            }
            if (IdList != "")
            {
                IdList = IdList.Substring(0, IdList.Length - 1);
            }
            return IdList;
        }




    }
}
